<template>
	<view class="contents" :style="'height:'+screenHeight+'px'">


		<view class="headers">
			<u-search @clickIcon="searchs" @search="searchs" placeholder="科室/医生名称" v-model="keyword"
				:showAction="false">
			</u-search>
		</view>

		<view class="listconent">
			<view class="mains" v-for="(item,index) in Departmen" :key="index">
				<view :class="index==indexshow?'left width color1':'left gary'" @click="isShow(index)">
					<span class="ftypespan">{{item.FullName}}</span>
				</view>
			</view>
		</view>
		<view class="right">
			<view class="rightchird" v-for="(citem,indexs) in DepartList" :key="indexs">
				<view @click="Scheduling(citem.DepartmentId)" style="padding: 0 50rpx;">
					<span class="">{{citem.DptName}}</span>
					<span style="float: right;"><u-icon size="22" name="arrow-right"></u-icon></span>
				</view>
			</view>

		</view>
		<u-modal v-if="doctorshow" v-model="show" title="预约挂号条款" confirm-color='#55aaff' :title-style="{ fontWeight: 'bold'}"
			confirm-text="前往就诊人管理" :show-cancel-button="false" @confirm="confirm" :mask-close-able="false">
			<view class="slot-content">
				
				<view class="" style="padding: 20px;">
					<view class="" style="text-align: center;">

					</view>
					<view class="">
						当前暂无就诊人，请前往就诊人管理页面添加就诊人。
					</view>
				</view>

			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex';
	export default {
		data() {
			return {
				scrollTop: 0,
				show:true,
				doctorshow: false,
				screenHeight: getApp().globalData.screenHeight - 44,
				showtext: false,
				indexshow: 0,
				index: 0,
				Departmen: [],
				keyword: '',
				DepartList: []
			}
		},

		computed: {
			...mapState(['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo']),
		},
		onLoad() {
			
			this.getjiuzhen()
			
		},
		onShow() {
			
			if (this.hasLogin) {
				uni.showLoading({
					title: '加载中'
				})
				this.$store.dispatch('getUserInfo');
				this.addDepartmen()
			} else {
			//	uni.hideLoading();
				uni.showModal({
					title: '提示',
					content: '登录后才可以操作',
					confirmText: '去登录',
					showCancel: false,
					success: function(res) {
						uni.reLaunch({
							url: '/pages/auth/login?name=selectDepartment'
						})
					}
				});
				return;
			}

		},
		methods: {
			confirm() {

				// 3秒后自动关闭
				// this.doctorshow = false;
				// 如果不想关闭，而单是清除loading状态，需要通过ref手动调用方法
				// this.$refs.uModal1.clearLoading();
				
				this.redirectToBindCard()
				
				uni.setStorageSync("URL","/pages/newregister/selectDepartment/selectDepartment")

			},
			redirectToBindCard() {
				const hospitalId = '39888';
				const redirectUri = 'http://dpzwx.xztongyong.cn/h5/#/pages/MedicalExamination/Healthcard/Healthcard';
				const bindCardUrl = this.constructBindCardUrl(hospitalId, redirectUri);
				window.location.href = bindCardUrl;
			},
			
			constructBindCardUrl(hospitalId, redirectUri) {
				const baseUrl = "https://h5-health.tengmed.com/h5/tencent/open/card/regist";
				const encodedRedirectUri = encodeURIComponent(redirectUri);
				let bindCardUrl = `${baseUrl}?hospitalId=${hospitalId}&redirect_uri=${encodedRedirectUri}`;
				return bindCardUrl;
			},
			
			
			
			
			
			getjiuzhen() {
				this.$request("patient", "defaultInfo")
				.then(res => {
					console.log("获取默认就诊人", res)
					if (res.code == 1) {
						this.doctorshow = false
					} else {
						this.doctorshow = true
					}
					
				});


			},
			Scheduling(DepartmentId) {
				console.log(DepartmentId)
				uni.navigateTo({
					url: `/pages/newregister/Scheduling/Scheduling?DepartmentId=${DepartmentId}`,
					fail(error) {
						console.log(error)
					}
				})
			},
			isShow(index) {
				this.indexshow = index
				this.DepartList = this.Departmen[index].DepartList
				// console.log(index)
				// console.log(this.DepartList)
			},
			addDepartmen() {
				this.$request('Company', 'ComAndDptlist').then(res => {
					if (res.code == 1) {
						this.Departmen = res.data
						this.DepartList = this.Departmen[0].DepartList
						this.indexshow = 0
						uni.hideLoading();
					} else {
					uni.hideLoading();
						console.log("获取失败")
					}

				})
				
			},
			searchs() {
				let keywords = this.keyword
				uni.navigateTo({
					url: `/pages/searchs/index?keyword=${keywords}`,
					fail(error) {
						console.log(error)
					}
				})
			}
		}
	}
</script>

<style>
	@import './selectDepartment.css'
</style>